using System;

namespace Edge.Common.ComponentModel.Parameters
{
    public class AbstractParametr : Attribute
    {
        private string _default;
        private string _name;
        private bool _isRequired;
        private bool _isDefaultForInvalid;
        private int _maxLength = -1;
        private int _minLength = -1;

        /// <summary>
        /// Creates a new WebParameterAttribute to load a field from an identically-named
        /// parameter in the Form/QueryString collection, if it exists.
        /// The parameter has no default value, and is not required
        /// </summary>
        public AbstractParametr()
        {
        }

        /// <summary>
        /// Creates a new WebParameterAttribute to load a field from the given parameter name
        /// The parameter has no default value, and is not required
        /// </summary>
        /// <param name="paramName">The key of a parameter in the Form or QueryString collections</param>
        public AbstractParametr(string paramName)
        {
            _name = paramName;
        }

        /// <summary>
        /// The name (key) of the parameter being bound against in the Request
        /// </summary>
        public string ParameterName
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// An optional default value to use if the parameter doesn't exist
        /// in the current Request, or null to clear
        /// </summary>
        /// <remarks>Whilst this is a bit unneccesary for a field, its
        /// handy for properties - can save all that <code>if(ViewState["x"]==null)</code>
        /// stuff...</remarks>
        public string DefaultValue
        {
            get { return _default; }
            set { _default = value; }
        }

        /// <summary>
        /// Whether the absence of the parameter, along with the absence
        /// of a default, causes an error, rather than the default
        /// behaviour which is that the field will just be skipped.
        /// The default is false.
        /// </summary>
        public bool IsRequired
        {
            get { return _isRequired; }
            set { _isRequired = value; }
        }

        /// <summary>
        /// Whether the default value can be used if the value passed to
        /// the page is invalid in some way (rejected by the type converter,
        /// or causes an error on the field/property set).
        /// The default is false.
        /// </summary>
        public bool IsDefaultUsedForInvalid
        {
            get { return _isDefaultForInvalid; }
            set { _isDefaultForInvalid = value; }
        }

        /// <summary>
        /// use for limit parametr max length (usually for text fileds)
        /// </summary>
        public int MaxLength
        {
            get { return _maxLength; }
            set { _maxLength = value; }
        }
    }
}